package cn.xinyangtong.manager.controller;

import cn.xinyangtong.common.pojo.DataResult;
import cn.xinyangtong.common.pojo.DefaultResult;
import cn.xinyangtong.manager.service.ContentService;
import cn.xinyangtong.pojo.TbContent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * 内容管理
 * Created by fengbo on 2017/6/17.
 */
@Controller
@RequestMapping("/content")
public class ContentController {

    @Autowired
    private ContentService contentService;

    /***
     * 添加内容
     * @param content
     * @return
     */
    @RequestMapping("/save")
    @ResponseBody
    public DefaultResult addContent(TbContent content) {
        return contentService.insertContent(content);
    }

    /**
     * 根据内容分类ID查询内容
     * @param categoryId
     * @param page
     * @param rows
     * @return
     */
    @RequestMapping("/query/list")
    @ResponseBody
    public DataResult getContentList(Long categoryId, Integer page, Integer rows) {
        return contentService.getContentList(categoryId, page, rows);
    }

    /****
     * 删除内容
     * @param ids
     * @return
     */
    @RequestMapping("/delete")
    @ResponseBody
    public DefaultResult deleteContent(Long[] ids) {
        return contentService.deleteByIds(ids);
    }

    /***
     * 修改内容
     * @param content
     * @return
     */
    @RequestMapping("/edit")
    @ResponseBody
    public DefaultResult editContent(TbContent content) {
        return contentService.updateContent(content);
    }
}
